package net.cyan.crud.view;

import net.cyan.commons.util.*;

/**
 * @author camel
 * @date 2009-9-2
 */
public class BaseTreeView extends AbstractPropertied<BaseTreeView>
        implements CheckBoxTreeView, NodePropertiedTreeView<BaseTreeView>
{
    public static final String NODECHECKABLE = "nodeCheckable";

    private String checkBoxName;

    private CheckBoxType checkBoxType;

    private boolean rootVisible = true;

    public BaseTreeView()
    {
        checkBoxType = CheckBoxType.none;
    }

    public BaseTreeView(String checkBoxName, CheckBoxType checkBoxType)
    {
        this.checkBoxName = checkBoxName;
        this.checkBoxType = checkBoxType;
    }

    public String getCheckBoxName()
    {
        return checkBoxName;
    }

    public CheckBoxType getCheckBoxType()
    {
        return checkBoxType;
    }

    public boolean isNodeCheckable(Object entity) throws Exception
    {
        Object obj = getProperty(entity, NODECHECKABLE);
        return obj == null || DataConvert.toBoolean(obj);
    }

    public BaseTreeView setNodeCheckable(Object checkable)
    {
        return setProperty(NODECHECKABLE, checkable);
    }

    public boolean isRootVisible()
    {
        return rootVisible;
    }

    public BaseTreeView setRootVisible(boolean rootVisible)
    {
        this.rootVisible = rootVisible;
        return this;
    }

    public BaseTreeView setHref(Object url)
    {
        return setProperty(HREF, url);
    }

    public String getHref(Object obj) throws Exception
    {
        return StringUtils.toString(getProperty(obj, HREF));
    }

    public BaseTreeView setTarget(Object action)
    {
        return setProperty(TARGET, action);
    }

    public Object getTarget(Object obj) throws Exception
    {
        return getProperty(obj, TARGET);
    }

    public BaseTreeView setAction(Object action)
    {
        return setProperty(ACTION, action);
    }

    public Object getAction(Object obj) throws Exception
    {
        return getProperty(obj, ACTION);
    }

    public BaseTreeView setIcon(Object icon)
    {
        return setProperty(ICON, icon);
    }

    public Object getIcon(Object obj) throws Exception
    {
        return getProperty(obj, ICON);
    }

    public BaseTreeView setIconClass(Object name)
    {
        return setProperty(ICONCLASS, name);
    }

    public String getIconClass(Object obj) throws Exception
    {
        return StringUtils.toString(getProperty(obj, ICONCLASS));
    }
}
